package db

import (
	"github.com/go-redis/redis"
	"github.com/spf13/viper"
)

type RedisConfig struct {
	Host     string
	Port     string
	Password string
	DB       int
	PoolSize int
}

var Redis *redis.Client

func NewRedis() {
	redisConfig := RedisConfig{
		Host:     viper.GetString("redis.host"),
		Port:     viper.GetString("redis.port"),
		Password: viper.GetString("redis.password"),
		DB:       viper.GetInt("redis.database"),
		PoolSize: viper.GetInt("redis.poolsize"),
	}

	Redis = redisConfig.Connect()
}

func (c *RedisConfig) Connect() *redis.Client {
	redisClient := redis.NewClient(&redis.Options{
		Addr:     c.Host + ":" + c.Port,
		Password: c.Password,
		DB:       c.DB,
		PoolSize: c.PoolSize,
	})
	return redisClient
}
